function validate_required(field,alerttxt)//验证是否为空
{
	with(field)
	{
		if(value==null||value==""){
			$(field).siblings(".Validform_checktip").html(alerttxt);
		//alert(alerttxt);
			return false;
		}else{
			$(field).siblings(".Validform_checktip").empty();
			return true;}
	}
}

function validate1(thisform)//验证用户名
{
	 if (validate_required(thisform,"昵称不能为空！")==false)
    {return false}
else
	{
		var name_str=thisform.value.trim();
		var reg=/^[\u4e00-\u9fa5_a-zA-Z0-9_]{1,20}$/;
			if(!reg.test(name_str))
			{
				$(thisform).siblings(".Validform_checktip").html("请输入合法的昵称");
				return false
			}else{
				$(thisform).siblings(".Validform_checktip").append(" <img src='../images/right.png' />");
				return true
			}
	}
	
	
}

function validate2(thisform)//验证密码
{
		 if (validate_required(thisform,"密码不能为空！")==false)
    {return false}
else
	{
		var pass_str=thisform.value.trim();
		var reg=/^[A-Za-z0-9]{1,20}$/;
			if(!reg.test(pass_str))
			{
				$(thisform).siblings(".Validform_checktip").html("请输入合法的密码");
				return false
			}else{
				$(thisform).siblings(".Validform_checktip").append(" <img src='../images/right.png' />");
				return true
			}
	}
}

function validate3(thisform)//密码确认
{
 if (validate_required(thisform,"请输入密码！")==false)
    {return false}
else
	{
	var str1=eval(document.getElementById('upassword')).value;
	var str2=thisform.value.trim();
		if(equals(str1, str2)==true){
		
		$(thisform).siblings(".Validform_checktip").append(" <img src='../images/right.png' />");
		return true
	}else{
		$(thisform).siblings(".Validform_checktip").html("两次输入不一致");	
		return false
	}
	}
	function equals(str1, str2)   
{   
    if(str1 === str2)   
    {   

        return true;   
    }

    return false;   
}
}

function validate4(thisform)//验证邮箱
{
		 if (validate_required(thisform,"邮箱不能为空！")==false)
    {return false}
else
	{
		var mail_str=thisform.value.trim();
		var reg= /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
			if(!reg.test(mail_str))
			{
				$(thisform).siblings(".Validform_checktip").html("请输入合法的邮箱地址");
			}else{
				$(thisform).siblings(".Validform_checktip").append(" <img src='../images/right.png' />");
			}
	}

}

$("#res").click(function()//清除提示
{
		document.getElementById("uname").focus();
	clear();

});
function clear()
{
	$(".Validform_checktip").empty();
}
$("#submit").click(function(){
	var right_logo=$(".Validform_checktip img");
	if(right_logo.length==4){
		document.formreg.action="userRegister.jsp";
		formreg.submit();
	}
});